package test;
import java.io.File;
import java.io.FileReader;
import org.junit.Test;
import parser.MiniP;
import parser.Start;

public class MiniPMSN extends TestCaseOutput {
    private final static String DATA = "data/";
    private final static String RESULT = "result/";
    private final static String FILE_EXTENSION = ".calc";
    private final static String RESULT_EXTENSION = ".msn.res";

    private void assertCorrectOutput(String testName) {
        String fullName = testName + FILE_EXTENSION;
        interactive(DATA + fullName);
        assertOutput(new File(RESULT + fullName + RESULT_EXTENSION));
    }

    @Test
	public void test() {
		assertCorrectOutput("test");
	}
	
	@Test
	public void test2() {
		assertCorrectOutput("test2");
	}
	
	@Test
	public void test3() {
		assertCorrectOutput("test3");
	}
	
	@Test
	public void test4() {
		assertCorrectOutput("test4");
	}

    private static void interactive(String arg) {
        try {
            MiniP parser = new MiniP(new FileReader(arg));
            Start start = parser.start();
            MSNVisitor v = new MSNVisitor();
            int msn = (Integer) start.jjtAccept(v, null);
            System.out.println("MSN: " + msn);
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }

    public static void main(String[] args) {
        interactive(args[0]);
    }
}